package com.yinshu.teleshield.tkbase.base.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.groups.Default;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 包括id、create_time、creator字段的表继承的基础实体
 *
 * @author yangjunxiong
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode
public class TKSuperEntity<T> implements Serializable {
    public static final String ID_FIELD = "id";
    public static final String CREATE_TIME = "createTime";
    public static final String CREATE_TIME_FIELD = "create_time";
    public static final String CREATOR = "creator";

    public static final String UPDATER = "updater";
    public static final String UPDATED_TIME = "updateTime";
    public static final String UPDATE_TIME_FIELD = "update_time";
    public static final String DELETED = "deleted";

    private static final long serialVersionUID = -4603650115461757622L;

    @TableId(value = ID_FIELD, type = IdType.AUTO)
    @Schema(description = "主键")
    @NotNull(message = "id不能为空", groups = Update.class)
    protected T id;

    @Schema(description = "创建时间")
    @TableField(value = CREATE_TIME_FIELD, fill = FieldFill.INSERT)
//    @LocalDateTimeJsonFormat
    protected LocalDateTime createTime;

    @Schema(description = "创建人ID")
    @TableField(value = CREATOR, fill = FieldFill.INSERT)
    protected Long creator;

    @Schema(description = "租户编号",example = "1")
    @TableField(value = "tenant_id", fill = FieldFill.INSERT)
    private Long tenantId;

    @Schema(description = "最后修改时间")
    @TableField(value = UPDATE_TIME_FIELD, fill = FieldFill.INSERT_UPDATE)
//    @LocalDateTimeJsonFormat
    protected LocalDateTime updateTime;

    @Schema(description = "最后修改人ID")
    @TableField(value = UPDATER, fill = FieldFill.INSERT_UPDATE)
    protected Long updater;

    @Schema(description = "是否删除", example = "0", allowableValues = {"0", "1"})
    @TableField(value = DELETED)
    private Integer deleted;

    /**
     * 保存和缺省验证组
     */
    public interface Save extends Default {

    }

    /**
     * 更新和缺省验证组
     */
    public interface Update extends Default {

    }
}
